package com.qf.advice;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * 环绕增强类
 */
public class MyAroundAdvice implements MethodInterceptor {
    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        //执行原始方法:必须调用原始方法，如果不调用，原始方法不会执行
        Object result= null;
        try {
            System.out.println("前置");
            result = methodInvocation.proceed();
            System.out.println("后置");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            System.out.println("异常");
        } finally {
            System.out.println("无论有没有异常都执行");
        }
        return result;
    }
}
